package vip.xiaonuo.modular.encryptAndDecrypt;

import org.springframework.web.bind.annotation.*;
import vip.xiaonuo.core.annotion.Decrypt;
import vip.xiaonuo.core.annotion.Encrypt;
import vip.xiaonuo.core.pojo.response.ResponseData;
import vip.xiaonuo.core.pojo.response.SuccessResponseData;
import vip.xiaonuo.core.util.RsaUtil;
import vip.xiaonuo.sys.modular.auth.service.AuthService;
import vip.xiaonuo.sys.modular.user.param.SysUserParam;
import vip.xiaonuo.sys.modular.user.service.SysUserService;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 加密解密测试demo controller
 *
 * @author zhangbixi
 * @date
 */
@RestController
@RequestMapping("/demo")
public class EncryAndDecryController {

    @Resource
    private SysUserService sysUserService;
    @Resource
    private AuthService authService;
    /**
     *  获取公钥接口
     *
     * @author zhangbixi
     * @date 2021/7/27 17:50
     */
    @GetMapping("/getKey")
    public ResponseData getKey(){
        System.out.println(RsaUtil.getPublicKey());
        Map<String , Object> map = new HashMap<>();
        map.put("publickey",RsaUtil.getPublicKey());
        map.put("token",authService.login("superAdmin","123456"));
        return new SuccessResponseData(map);
    }

    /**
     *  加密添加用户测试接口
     *
     * @author zhangbixi
     * @date 2021/7/27 17:50
     * @param sysUserParam
     * @return com.cn.xiaonuo.core.pojo.response.ResponseData
     */
    @PostMapping("/postTest")
    @Decrypt
    @Encrypt
    public ResponseData postTest(@RequestBody SysUserParam sysUserParam){
//        sysUserService.add(sysUserParam);
        return new SuccessResponseData("添加成功");
    }

    /**
     *
     *
     * @author zhangbixi
     * @date 2021/7/27 17:58
     * @param sysUserParam
     * @return com.cn.xiaonuo.core.pojo.response.ResponseData
     */
    @GetMapping("/getTest")
    @Decrypt
    @Encrypt
    public ResponseData getTest(SysUserParam sysUserParam){
        return new SuccessResponseData(sysUserService.getBaseMapper().selectById(sysUserParam));
    }
}
